/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TIMESTAMP_H_
#define TIMESTAMP_H_

#include <iostream>
#include <time.h>

namespace tri{



class TTimeStamp
{
public:
    TTimeStamp();
    
    /**
     * Create a time object from the time in seconds
     * 
     * @param sec: Seconds since the EPOCH
     */
    TTimeStamp(time_t sec);
    
    virtual ~TTimeStamp();
    
    /**
     * Set the time for this object in seconds
     */
    void setTimeInSeconds(time_t t);
    
    /**
     * Get the time in seconds.
     * 
     * @return Stored time in seconds
     */
    time_t get();
    
    
    /**
     * Get the difference between two time stamps in sceonds
     * 
     * @return Seconds differences. This may be negative
     */
    time_t diff(TTimeStamp& t);
    
    /**
     * Get the current time in seconds
     * since the EPOCH
     * 
     * @return Time in seconds
     */
    static time_t now();
    
    /**
     * Return the amount of hours from the seconds 
     * as a floating point number
     * 
     * @return Hours as a float
     */
    static float min2hour(float min);
    
    /**
     * Return the amount of minutes from the hours 
     * as a floating point number
     * 
     * @return seconds as a float
     */
    static float hour2min(float hours);
    
    /**
     * Return the amount of minutes from the seconds 
     * as a floating point number
     * 
     * @return minutes as a float
     */
    static float min2sec(float min);
    
    /**
     * Return the amount of minutes from the seconds 
     * as a floating point number
     * 
     * @return minutes as a float
     */
    static float sec2min(float sec);
    
    /**
     * Return the amount of hours from the seconds 
     * as a floating point number
     * 
     * @return Hours as a float
     */
    static float day2hour(float day);
    
    /**
     * Return the amount of minutes from the hours 
     * as a floating point number
     * 
     * @return seconds as a float
     */
    static float hour2day(float hours); 
    
    bool operator==(TTimeStamp&);
    
private:
    time_t _sec;
};

}

std::ostream &operator<<(std::ostream& out,tri::TTimeStamp& h);

#endif /*TIMESTAMP_H_*/
